package org.example.server.service;

import cn.hutool.core.util.IdUtil;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.server.bean.PictureBean;
import org.example.server.mapper.PictureMapper;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class PictureService {
    @Resource
    private PictureMapper pictureMapper;

    public void save(PictureBean pictureBean){
        log.info("save {} 开始检验数据完整性", pictureBean);
      if(pictureBean.getTitle()==null)
          throw new RuntimeException("title 不能为空");
      if(pictureBean.getUrl()==null)
          throw new RuntimeException("url 不能为空");
      if (pictureBean.getOriginTitle()==null)
          throw new RuntimeException("originTitle 不能为空");
//      if (pictureBean.getAccountId()==null)
//          throw new RuntimeException("accountId 不能为空");
      log.info("save  数据完整性校验通过");
      pictureBean.setId(IdUtil.getSnowflakeNextId());
      pictureBean.setCreateTime(System.currentTimeMillis());
      pictureBean.setUpdateTime(pictureBean.getCreateTime());
      pictureBean.setUrl(pictureBean.getUrl());
      pictureBean.setTitle(pictureBean.getTitle());
      pictureBean.setOriginTitle(pictureBean.getOriginTitle());
      log.info("开始执行sql语句");
      pictureMapper.insert(pictureBean);
    }


}
